<?php
/**
 * 解密并执行下载
 */
require('./inc/functions.php');
if (!isset($_GET['sid']) || !isset($_GET['i'])) {
    die(json_encode(['code' => 500, 'msg' => '来源错误']));
}
$info = wb_get_json($_GET['sid']);
if (empty($info) || !isset($info['files'][(int)$_GET['i']]['savename'])) {
    die(json_encode(['code' => 500, 'msg' => '文件已过期']));
}
$file_path = BASIC_PATH . $info['files'][(int)$_GET['i']]['savepath'] . $info['files'][(int)$_GET['i']]['savename'];
if (!file_exists($file_path)) {
    die(json_encode(['code' => 500, 'msg' => '文件已过期删除']));
}

$filename = date('m-d-His', time()) . '_' . $info['files'][(int)$_GET['i']]['name'];
header('content-disposition:attachment;filename=' . $filename);
header('content-length:' . $info['files'][(int)$_GET['i']]['size']);
readfile($file_path);